import DList from "@/components/dlist";

export default {
  data () {
    return {
      loading: false,
      finished: false,
      page: 1,
      pullLoading: false,
      starStoreData:[],
      memberInfo:{},
      accumulate_reward:"",
      title: ''
    };
  },

  activated () {
    this.onLoad();
  },

  methods: {

    async getRewardList(){
      if (this.loading === true || this.finished === true) {
        return;
      }
      this.loading = true;
      let { data, result, msg } = await $http.post("plugin.big-screen.frontend.reward.list",{page: this.page},'.');
      // console.log(data, result, msg);
      if (result === 0) {
        Toast(msg);
        return;
      }
      if (data.data.length === 0 || data.data.length < data.per_page || data.current_page === data.last_page) {
        this.finished = true;
      }
      this.page++;
      this.starStoreData.push(...data.data);
      this.loading = false;
    },
    async loadTop(){
      let { data, result, msg } = await $http.post("plugin.big-screen.frontend.reward.list",{page: 1},'.');
      if (result === 0) {
        Toast(msg);
        return;
      }
      this.starStoreData = [];
      this.starStoreData.push(...data.data);
      this.pullLoading = false;
    },
    async getMemberData(){
      let { data, result, msg } = await $http.post("plugin.big-screen.frontend.reward.index",{});
      if (result === 0) {
        Toast(msg);
        return;
      }
      this.accumulate_reward = data.sum_amount;
      this.memberInfo = data.member;
      this.title = this.fun.getPluginSetting('big_screen.plugin_name','农优云');
      this.fun.setWXTitle(this.title);
    },
    onLoad(){
      this.getMemberData();
      this.getRewardList();
    }
  },

  components: {
    DList
  },
};